package com.yanqu.road.dao.impl.activity.fellingtrees;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.fellingtrees.config.FellingTreesElixirConfig;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class FellingTreesElixirConfigDaoImpl extends TempDao {

    private static String getFellingTreesElixirConfigSql = "select * from `t_s_activity_ftrees_elixir` where `activityId`=?";

    public Map<Integer, FellingTreesElixirConfig> getFellingTreesElixirConfigMap(int activityId) {
        Map<Integer, FellingTreesElixirConfig> map = new ConcurrentHashMap<>();
        ResultSet rs = null;
        CallableStatement call = null;
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getFellingTreesElixirConfigSql);
            int i = 1;
            call.setInt(i++, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FellingTreesElixirConfig fellingTreesElixirConfig = new FellingTreesElixirConfig();
                fellingTreesElixirConfig.setActivityId(rs.getInt("activityId"));
                fellingTreesElixirConfig.setId(rs.getInt("id"));
                fellingTreesElixirConfig.setIcon(rs.getString("icon"));
                fellingTreesElixirConfig.setQuality(rs.getInt("quality"));
                fellingTreesElixirConfig.setType(rs.getInt("type"));
                fellingTreesElixirConfig.setParam(rs.getString("param"));
                fellingTreesElixirConfig.setTimes(rs.getInt("times"));
                fellingTreesElixirConfig.setEnergy(rs.getInt("energy"));
                fellingTreesElixirConfig.setMaterials(rs.getString("materials"));
                map.put(fellingTreesElixirConfig.getId(), fellingTreesElixirConfig);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
        } finally {
            getDb().closeConnection(call, rs);
        }
        return map;
    }

}
